<template>
  <!-- 左侧导航 -->
  <div class="wrap">
    <van-sidebar v-model="activeKey">
      <van-sidebar-item
        v-for="(item,index) in sideBarList"
        :key="index"
        :title="item.title"
        @click="sidebarChange(item.id)"
      />
    </van-sidebar>
  </div>
</template>
<script>
export default {
  data() {
    return {
      activeKey: 0,
      type: "1",
      sideBarList: [
        {
          id: "1",
          title: "推荐",
        },
        {
          id: "2",
          title: "出行",
        },
        {
          id: "3",
          title: "睡眠",
        },
        {
          id: "4",
          title: "美食",
        },
        {
          id: "5",
          title: "美护",
        },
        {
          id: "6",
          title: "休闲",
        },
        {
          id: "7",
          title: "儿童",
        },
        {
          id: "8",
          title: "推荐",
        },
        {
          id: "9",
          title: "家务",
        },
        {
          id: "10",
          title: "空间",
        },
      ],
    };
  },
  mounted() {
    //做一次默认请求
    this.$store.dispatch("classifyList/getClassifyList", {
      type: this.type,
    });
  },
  methods: {
    sidebarChange(id) {
      this.type = id;
      this.$store.commit("classifyList/changetype", id); //调用SideBar里面的mutations
      //每次点击也要做请求
      this.$store.dispatch("classifyList/getClassifyList", {
        type: this.type,
      });
    },
  },
};
</script>
<style lang="stylus" scoped>
.wrap {
  height: 100%;
  width: 74px;
  border-right: 1px solid #F3F3F3;
  position: relative;

}

.van-sidebar {
  position: absolute;
  left: 0;
  top: 0;
  text-align: center;
  width: 74px;
  height: 100%;

  .van-sidebar-item {
    background: #fff;
    font-size: 14px;
    color: #2D2D2D;
    height: 44px;
    padding: 12px 10px;
    border-right: 1px solid #F3F3F3;    
    font-family: PingFang SC;
  }

  .van-sidebar-item--select {
    color: #B71A35;
    border-right: 1px solid #fff;
    border-bottom: 1px solid #F3F3F3;
    border-top: 1px solid #F3F3F3;
    font-size: 16px;

    &::before {
      background: #FFF;
    }
  }

  .van-sidebar-item--select:nth-child(1) {
    border-top: none;
  }
}
</style>